package
{
	import core.HtmlView;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.geom.Point;
	import flash.system.Security;
	import flash.ui.Mouse;
	import flash.ui.MouseCursorData;
	import flash.utils.getTimer;
	
	import org.aisy.display.USprite;

	public class Main extends USprite
	{
		static public var IM:Main;
		protected var NAME:String;
		protected var _cursor_v_splitName:String;
		[Embed(source="image/cursor_v_split.png")]
		protected var _cursor_v_splitE:Class;
		
		public function Main()
		{
			try {
				Security.allowDomain("*");
				Security.allowInsecureDomain("*");
			} catch (error:Error) {}
		}
		
		public function connect(im:*):void
		{
			im.stage.align = StageAlign.TOP_LEFT;
			im.stage.scaleMode = StageScaleMode.NO_SCALE;
			
			IM = this;
			
			NAME = "" + getTimer();
			_cursor_v_splitName = "cursor_v_split";
			
			var _v:Vector.<BitmapData> = new Vector.<BitmapData>();
			_v[0] = (new _cursor_v_splitE() as Bitmap).bitmapData;
			
			var _mouseCursorData:MouseCursorData = new MouseCursorData();
			_mouseCursorData.hotSpot = new Point(_v[0].width >> 1, _v[0].height >> 1);
			_mouseCursorData.data = _v;
			
			Mouse.registerCursor(_cursor_v_splitName + NAME, _mouseCursorData);
			
			_mouseCursorData = null;
			_v = null;
			_cursor_v_splitE = null;
			
			this.addChild(new HtmlView());
			im.addChild(this);
			im = null;
		}
		
		public function setCursor(cursor:String):void
		{
			switch (cursor) {
				case _cursor_v_splitName:
					cursor += NAME;
					break;
			}
			Mouse.cursor = cursor;
		}
		
		override public function clear():void
		{
			Mouse.unregisterCursor(_cursor_v_splitName + NAME);
			super.clear();
			_cursor_v_splitName = null;
			NAME = null;
			IM = null;
		}
		
	}
}